import request from '@/utils/request'

// 查询论坛列表
export function listForum(query) {
  return request({
    url: '/forum/list',
    method: 'get',
    params: query
  })
}

// 查询发送人论坛详细
export function getForumUserId(userId) {
  return request({
    url: '/forum/forum/' + userId,
    method: 'get'
  })
}

// 查询论坛详细
export function getForum(forumId) {
  return request({
    url: '/forum/' + forumId,
    method: 'get'
  })
}

// 新增论坛
export function addForum(data) {
  return request({
    url: '/forum',
    method: 'post',
    data: data
  })
}

// 修改论坛
export function updateForum(data) {
  return request({
    url: '/forum',
    method: 'put',
    data: data
  })
}

/**
 * 修改论坛举报状态
 */
export function updateReport(forumId, report) {
  const data = {
    forumId,
    report
  }
  return request({
    url: '/forum/updateReport',
    method: 'put',
    data: data
  })
}

/**
 * 浏览量+1
 */
export function updateClickNumber(data) {
  return request({
    url: '/forum/updateClick',
    method: 'put',
    data: data
  })
}

/**
 * 修改论坛状态
 */
export function updateStatus(data, type) {
  const data1 = JSON.parse(data)
  if (type == 'agree') {
    data1.status = '1'
  } else if (type == 'refuse') {
    data1.status = '2'
  }
  return request({
    url: '/forum/updateStatus',
    method: 'put',
    data: data1
  })
}

/**
 * 点赞量+1
 */
export function updateFabulousNumber(data) {
  return request({
    url: '/forum/updateFabulous',
    method: 'put',
    data: data
  })
}

/**
 * 收藏量+1
 */
export function updateCollectionNumber(data) {
  return request({
    url: '/forum/updateCollection',
    method: 'put',
    data: data
  })
}
/**
 * 回复量+1
 */
export function updateReplyNumber(forumId) {
  const data = {
    forumId
  }
  return request({
    url: '/forum/updateReply',
    method: 'put',
    data: data
  })
}

/**
 * 修改论坛结帖状态
 */
export function updateAccept(forumId, accept) {
  const data = {
    forumId,
    accept
  }
  return request({
    url: '/forum/updateAccept',
    method: 'put',
    data: data
  })
}

// 删除论坛
export function delForum(forumId) {
  return request({
    url: '/forum/' + forumId,
    method: 'delete'
  })
}

/**
 * 批量修改论坛举报状态为 1 成功
 */
export function delReport1(forumId) {
  return request({
    url: '/forum/delReport1/' + forumId,
    method: 'delete'
  })
}

/**
 * 批量修改论坛举报状态为 2 不成功
 */
export function delReport2(forumId) {
  return request({
    url: '/forum/delReport2/' + forumId,
    method: 'delete'
  })
}

/**
 * 批量修改论坛结帖状态为 0
 */
export function delAccept0(forumId) {
  return request({
    url: '/forum/delAccept0/' + forumId,
    method: 'delete'
  })
}

/**
 * 批量修改论坛结帖状态为 1
 */
export function delAccept1(forumId) {
  return request({
    url: '/forum/delAccept1/' + forumId,
    method: 'delete'
  })
}
